<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="java.math.BigDecimal" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Date" %>
<%
    JSONObject jsonData = new JSONObject();
    RecordSet rs = new RecordSet();
    String resourceid = Util.null2String(request.getParameter("resourceid"));
    String sqrq = Util.null2String(request.getParameter("sqrq"));
    rs.executeQuery("select datediff(minute, concat(signindate,' ',signintime)," +
            "concat(signoutdate,' ',signouttime))  from kq_format_detail " +
            "where resourceid=? and kqdate =?", resourceid, sqrq);
    rs.next();
    String worktime = Util.null2String(rs.getString(1));
    String hours = fDivide(worktime,"60",2);
    jsonData.put("hours", hours);
    out.print(jsonData.toJSONString());
%>
<%!
    private static String getDifferHour(String startDateTime, String endDateTime) {
        long mills = 0;
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date parse1 = dateFormat.parse(startDateTime);
            Date parse2 = dateFormat.parse(endDateTime);
            mills = parse2.getTime() - parse1.getTime();
        } catch (Exception e) {
            e.printStackTrace();
        }
        BigDecimal fz = new BigDecimal(mills);
        BigDecimal fm = new BigDecimal(60 * 60 * 1000);
        BigDecimal bwtHours = fz.divide(fm, 2, BigDecimal.ROUND_HALF_UP);
        return bwtHours.toString();
    }

    public static String fDivide(String a, String b, int n) {
        a = isZero(a);
        b = isZero(b);
        BigDecimal bg1 = new BigDecimal(a);
        BigDecimal bg2 = new BigDecimal(b);

        BigDecimal bd = bg1.divide(bg2, n, BigDecimal.ROUND_HALF_UP);
        return bd.toString();
    }
    public static String isZero(String a) {
        if ("".equals(a)) {
            a = "0";
        }
        return a;
    }
%>